package net.lym.es.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * ES测试 : 文档数据删除
 */
public class ESTest_Doc_Delete {
    public static void main(String[] args) throws Exception {
        // 创建 ES 客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
        );

        // 删除文档 - 请求对象
        DeleteRequest request = new DeleteRequest();
        // 设置索引及唯一性标识
        request.index("user").id("1001");
        // 客户端发送请求，获取响应对象
        DeleteResponse response = esClient.delete(request, RequestOptions.DEFAULT);
        // 打印信息
        System.out.println(response.toString());

        // 关闭 ES 客户端
        esClient.close();
    }
}
